package com.bot.nft.module.dc.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.dc.domain.bo.DcNftInfoBo;
import com.bot.nft.module.dc.domain.bo.DcNftQueryBo;
import com.bot.nft.module.dc.domain.vo.DcNftInfoVo;
import com.bot.nft.module.dc.domain.vo.NftDictVo;
import com.bot.nft.module.dc.service.IDcNftInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author RenXiaoZheng
 * @since 2024-01-24
 */
@RestController
@RequestMapping("/nft")
public class DcNftInfoController {

    @Resource
    IDcNftInfoService dcNftService;

    //添加藏品信息
    @RequestMapping("/addNft.do")
    public CommonResult addNft(@RequestBody @Valid DcNftInfoBo dcNftInfoBo) {
        Boolean boo = dcNftService.addDcNftInfo(dcNftInfoBo);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("添加成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("添加失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //分页查询藏品信息
    @RequestMapping("/{pageNo}/{pageSize}/select.do")
    public CommonResult<IPage> selectDcNft(@RequestBody DcNftQueryBo dcNftQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        IPage<DcNftInfoVo> dcNftInfoVoPageInfo = dcNftService.queryDcNftInfo(dcNftQueryBo.getType(), dcNftQueryBo.getKeyword(), dcNftQueryBo.getStatus(), pageNo, pageSize, dcNftQueryBo.getShow());
        CommonResult<IPage> commonResult = new CommonResult<>();
        commonResult.setMsg("查询成功");
        commonResult.setCode(200);
        commonResult.setData(dcNftInfoVoPageInfo);
        return commonResult;
    }

    //展示藏品或者不展示藏品
    @RequestMapping("/{id}/{num}/showNft.do")
    public CommonResult belowNftInfo(@PathVariable("id") String id, @PathVariable("num") Integer num) {
        //调用接口
        Boolean boo = dcNftService.showDcNftInfo(id, num);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //查看藏品信息
    @RequestMapping("/{id}/getDcNft.do")
    public CommonResult<DcNftInfoVo> getDcNft(@PathVariable("id") String id) {
        //调用接口
        DcNftInfoVo dcNftInfo = dcNftService.getDcNftInfo(id);
        //查看中间表
        CommonResult<DcNftInfoVo> commonResult = new CommonResult<>();
        if (ObjectUtil.isNotNull(dcNftInfo)) {
            commonResult.setMsg("查看成功");
            commonResult.setCode(200);
            commonResult.setData(dcNftInfo);
        } else {
            commonResult.setMsg("查看失败");
            commonResult.setCode(500);
            commonResult.setData(null);
        }
        return commonResult;
    }

    //发售藏品
    @GetMapping("/{id}/sale.do")
    public CommonResult saleNftInfo(@PathVariable("id") String id) {
        //调用接口
        Boolean boo = dcNftService.saleDcNftInfo(id);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //下架藏品
    @GetMapping("/{id}/below.do")
    public CommonResult belowNftInfo(@PathVariable("id") String id) {
        //调用接口
        Boolean boo = dcNftService.belowDcNftInfo(id);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //删除藏品
    @RequestMapping("/{id}/delNft.do")
    public CommonResult delNftInfo(@PathVariable("id") String id) {
        //调用接口
        Boolean boo = dcNftService.delDcNftInfo(id);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //修改藏品信息
    @RequestMapping("/modify.do")
    public CommonResult modifyNft(@RequestBody DcNftInfoBo dcNftInfoBo) {
        Boolean boo = dcNftService.updateDcNftInfo(dcNftInfoBo);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("操作成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("操作失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }

    //上架藏品
    @RequestMapping("/upperDcNft.do")
    public CommonResult upperDcNft(@RequestParam("id") String id) {
        //调用接口
        Boolean boo = dcNftService.saleDcNftInfo(id);
        CommonResult commonResult = new CommonResult<>();
        if (boo) {
            commonResult.setMsg("上架成功");
            commonResult.setCode(200);
        } else {
            commonResult.setMsg("上架失败");
            commonResult.setCode(500);
        }
        return commonResult;
    }


    //查看藏品信息
    @RequestMapping("/{type}/showDict.do")
    public CommonResult<List<NftDictVo>> showDict(@PathVariable("type") String type) {
        //调用接口
        List<NftDictVo> nftDictVos = dcNftService.showDict(type);
        //查看中间表
        CommonResult<List<NftDictVo>> commonResult = new CommonResult<>();
        if (ObjectUtil.isNotNull(nftDictVos)) {
            commonResult.setMsg("查看成功");
            commonResult.setCode(200);
            commonResult.setData(nftDictVos);
        } else {
            commonResult.setMsg("查看失败");
            commonResult.setCode(500);
            commonResult.setData(null);
        }
        return commonResult;
    }

}
